<template>
	<m-layout title="領取記錄" gap="24">
		<m-block gap="0 24" spa="0 0 12" v-for="(item, index) in listArr">
			<view class="li p-12">
				<view class="ptb-8 flex-between ptb-40">
					<text class="fs26">{{ item.ctime.replace('T', ' ').slice(0, 16) }}</text>
					<view class="flex fs26 ai-baseline">
						<text>{{ item.rewardAmount }}</text>
						<text class="ml-4 fs24">{{ coinConfig[item.rewardCoinid]['coinname'] }}</text>
					</view>
				</view>
			</view>
		</m-block>
		<m-loading :list="listArr" :pageIndex="pageIndex" :pageCount="pageCount" :loading="isLoading" />
	</m-layout>
</template>

<script>
import { mapState } from 'vuex';
import { creditdetal } from '@/api/Trade.js';
export default {
	data() {
		return {
			credittype: '41', // 农场收益
			listArr: [],
			pageIndex: 1,
			pageSize: 10,
			pageCount: 1,
			isLoading: false,
			coinid: 4
		};
	},
	computed: {
		...mapState({
			userinfo: (state) => state.user.userinfo,
			coinConfig: (state) => state.general.coinConfig
		})
	},
	onLoad() {
		this.getData();
	},
	methods: {
		// 初始化
		reset() {
			this.pageCount = 1;
			this.pageIndex = 1;
			this.getData();
		},
		// 获取转让记录列表
		async getData() {
			if (this.pageIndex > this.pageCount) return;
			this.isLoading = true;
			const { list, pageCount, success } = await creditdetal({
				credittype: this.credittype,
				pageSize: this.pageSize,
				pageIndex: this.pageIndex
			});
			this.isLoading = false;
			this.pageCount = pageCount;
			if (this.pageIndex <= 1) {
				this.listArr = list;
			} else {
				this.listArr = [...this.listArr, ...list];
			}
			this.pageIndex++;
			uni.stopPullDownRefresh();
		}
	},
	onPullDownRefresh() {
		this.reset();
	},
	onReachBottom() {
		this.getData();
		console.log('触底了');
	}
};
</script>

<style lang="scss"></style>
